package PlaneGame.CODE;

import java.io.*;

public class GameData {
    String filePath;
    File dataFile;
    DataOutputStream writer;
    DataInputStream reader;
    public GameData() {
        filePath="src/PlaneGame/Data.txt";
        dataFile=new File(filePath);
    }
    void xie(int score){
        int record;
        record=du();
        if(score<record){
            return;
        }
        try {
            writer=new DataOutputStream(new FileOutputStream(dataFile));
            writer.writeInt(score);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    int du(){
        int score;
        try {
            reader=new DataInputStream(new FileInputStream(dataFile));
            score=reader.readInt();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                reader.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return score;
    }
}
